<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<meta name="description" content="">
		<meta name="author" content="">
		<title>新增账号</title>
		<link rel="stylesheet" href="../../../css/base.css" />
		<link rel="stylesheet" href="../../../css/common.css" />
		<!-- Bootstrap Core CSS -->
		<link href="../../../sbadmin/bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
		<!-- MetisMenu CSS -->
		<link href="../../../sbadmin/bower_components/metisMenu/dist/metisMenu.min.css" rel="stylesheet">
		<!-- DataTables CSS -->
		<link href="../../../sbadmin/bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.css" rel="stylesheet">
		<!-- Custom CSS -->
		<link href="../../../sbadmin/dist/css/sb-admin-2.css" rel="stylesheet">
		<!-- Custom Fonts -->
		<link href="../../../sbadmin/bower_components/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
		<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet" />
		<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
		<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
		<!--[if lt IE 9]>
	<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
	<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
	<![endif]-->
	</head>

	<body style="background:#fff;">
		<div class="container-fluid" style="background-color: #fff;">
			<div class="title">
				账号管理 > 新增账号
			</div>
			<div class="zl-ccbox">
				<div class="zl-cccc pr">
					<div class="edit-item clb">
						<div class="edit-item-tt fl"><em>*</em>账号：</div>
						<div class="edit-item-cc fl ml10">
							<input type="text" class="edit-input" id="accountName" />
						</div>
					</div>
					<div class="edit-item clb">
						<div class="edit-item-tt fl"><em>*</em>手机号：</div>
						<div class="edit-item-cc fl ml10">
							<input type="text" class="edit-input" id="phone" />
						</div>
					</div>
					<div class="edit-item clb">
						<div class="edit-item-tt fl"><em>*</em>角色：</div>
						<div class="edit-item-cc fl ml10">
							<select class="item-select" id="roleName">
								<option value="">请选择</option>
								<option value="1">管理员</option>
								<option value="2">前台</option>
							</select>
						</div>
					</div>
					<div class="edit-item clb">
						<div class="edit-item-tt fl">门店：</div>
						<div class="edit-item-cc fl ml10">
							<div class="clb" id="addListA">
								<!--<div class="asdList">门店1</div>-->
							</div>
							<div class="asctBox">
								城市选择：
								<select class="eic-select" style="width: 100px;" id="ctName"></select>
							</div>
							<div class="asctList">
								<ul class="asctLi clb">

								</ul>
							</div>
						</div>
					</div>
					<div class="edit-item clb">
						<div class="edit-item-tt fl"></div>
						<div class="edit-item-cc fl ml10">
							<a href="list.html" class="fl commqx-btn">取消</a>
							<a href="javascript:void(0)" class="fl commqr-btn ml15" id="addAccount">确定</a>
						</div>
					</div>
				</div>
			</div>

			<!-- jQuery -->
			<script src="../../../sbadmin/bower_components/jquery/dist/jquery.min.js"></script>
			<!-- Bootstrap Core JavaScript -->
			<script src="../../../sbadmin/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
			<!-- Metis Menu Plugin JavaScript -->
			<script src="../../../sbadmin/bower_components/metisMenu/dist/metisMenu.min.js"></script>
			<!-- DataTables JavaScript -->
			<script src="../../../sbadmin/bower_components/datatables/media/js/jquery.dataTables.min.js"></script>
			<script src="../../../sbadmin/bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.min.js"></script>
			<!-- Custom Theme JavaScript -->
			<script src="../../..//sbadmin/dist/js/sb-admin-2.js"></script>
			<!-- Page-Level Demo Scripts - Tables - Use for reference -->
			<script src="../../../js/layer/layer.js"></script>
			<script src="../../../js/common.js"></script>
			<script type="text/javascript" src="../../../js/jquery-ui.min.js"></script>
			<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>
	</body>
	<script>
		/*//角色
												$.ajax({
													url: "https://order.wz1996.wang/wzbg/role/all",
													type: 'get',
													contentType: 'application/json',
													success: function(data) {
														console.log(data);
														var html = "";
														for(var i = 0; i < data.length; i++) {
															html += "<option value=" + data[i].id + ">" + data[i].name + "</option>"
														}
														$("#roleName").html(html);
													},
													error: function(e) {
														layar(e.status);
													}
												});
										*/
		//城市
		$.ajax({
			url: "https://order.wz1996.wang/wzbg/openedcity/all",
			type: 'get',
			contentType: 'application/json',
			beforeSend: function(request) {
				request.setRequestHeader("token", localStorage.getItem("token"));
			},
			success: function(data) {
				console.log(data);
				//登录状态
				var html = "";
				if(data.code == "1") {
					html += "<option>--请选择--</option>"
					for(var i = 0; i < data.data.length; i++) {
						html += "<option id=" + data.data[i].cityId + " value=" + data.data[i].cityId + ">" + data.data[i].cityName + "</option>"
					}
					$("#ctName").html(html);
				} else if(data.code == "-1") {
					layar(data.msg);
					setTimeout("window.parent.frames.location.href='/xcxadmin/login.html'", 1000)
				} else {
					layar(data.msg);
				}
			},
			error: function(e) {
				errcode(e);
			}
		});

		$("#ctName").change(function() {
			var id = $("#ctName option:selected").attr("id");
			var user = {
				"store": {
					"cityId": id
				}
			}
			$.ajax({
				url: "https://order.wz1996.wang/wzbg/store/query",
				type: 'post',
				contentType: 'application/json',
				data: JSON.stringify(user),
				beforeSend: function(request) {
					request.setRequestHeader("token", localStorage.getItem("token"));
				},
				success: function(data) {
					console.log(data)
					if(data.code == "1") {
						var html = "";
						for(var i = 0; i < data.data.length; i++) {
							html += "<li id=" + data.data[i].store.id + ">" + data.data[i].store.name + "</li>"
						}
						$(".asctLi").html(html)

					} else if(data.code == "-1") {
						layar(data.msg);
						setTimeout("window.parent.frames.location.href='/xcxadmin/login.html'", 1000)
					} else {
						layar(data.msg);
					}
				},
				error: function(e) {
					errcode(e);
				}
			});

		});

		$(".asctLi").on("click", "li", function() {
			var hascur = $(this).hasClass("cur");
			var sid = $(this).attr("id");
			var html = $(this).html();
			if(hascur) {
				$(this).removeClass("cur");
				$("#addListA div").each(function(i) {
					var sdid = $("#addListA div").eq(i).attr("id");
					if(sid == sdid) {
						$("#addListA div").eq(i).remove();
					}
				})
			} else {
				$(this).addClass("cur");
				var apdhtml = "<div class='asdList' id=" + sid + ">" + html + "</div>";
				$("#addListA").append(apdhtml);
			}

		})

		//点上面下面没掉
		$("#addListA").on("click", "div", function() {
			nsid = "";
			var sid = $(this).attr("id");
			var sthis = $(this);
			sthis.remove();
			$(".asctLi li").each(function(i) {
				var sdid = $(".asctLi li").eq(i).attr("id");
				if(sid == sdid) {
					$(".asctLi li").eq(i).removeClass("cur");
					sthis.remove();
				}
			})
		})
		var allref = [];
		$("#addAccount").on('click', function() {
			allref = [];
			$(".asdList").each(function(index) {
				var ids = {};
				ids['id'] = $(".asdList").eq(index).attr("id");
				ids['name'] = $(".asdList").eq(index).html();
				allref.push(ids);
			});
			console.log(allref)
			var accountName = $("#accountName").val();
			var phone = $("#phone").val();
			var typeName = $("#roleName option:selected").val();
			/*var roleArr = [{
				"id": roleName,
				"name": $("#roleName option:selected").html()
			}]*/
			if(accountName == "") {
				layar("请填写账号！");
			} else if(phone == "") {
				layar("请填写手机号！");
			} else if(typeName == "" || typeName == null || typeName == undefined) {
				layar("请选择角色！");
			} else {
				var post_data = {
					"login": {
						"identifier": accountName,
						"credential": "123456"
					},
					"stores": allref,
					"user": {
						"phone": phone,
						"type": typeName
					}
				}
				$.ajax({
					url: "https://order.wz1996.wang/wzbg/user/add",
					type: 'post',
					contentType: 'application/json',
					data: JSON.stringify(post_data),
					beforeSend: function(request) {
						request.setRequestHeader("token", localStorage.getItem("token"));
					},
					success: function(data) {
						console.log(data)
						if(data.code == "1") {
							layar("添加成功!");
							setTimeout("window.location.href='list.html'", 1000)
						} else if(data.code == "-1") {
							layar(data.msg);
							setTimeout("window.parent.frames.location.href='/xcxadmin/login.html'", 1000)
						} else {
							layar(data.msg);
						}
					},
					error: function(e) {
						layar("账号与手机号码不能重复！");
					}
				});
			}

		})
	</script>

</html>